// pages/activeHits/index.js
const {
  post,
  dateFormat
} = getApp();
Page({
  data: {
    params: {
      start_time: "",
      end_time: "",
      page: 1,
      pageSize: 20
    },
    dataList: [],
    show: false,
    showLoading: true,
    showPage: false,
    minDate: new Date(2020, 0, 1).getTime(),
    defaultDate: [new Date().getTime(), new Date(new Date().setDate(new Date().getDate() + 1)).getTime()]
  },
  // 初始化加载
  onLoad: function () {
    this.getList();
  },
  // 获取数据
  getList() {
    if (this.data.showLoading) {
      post("/member/click/list", this.data.params).then(res => {
        if (res.result == 1) {
          const dataList = this.data.dataList.concat(res.data);
          this.setData({
            dataList: dataList,
            showPage: true
          });
          if (res.data.length < this.data.params.pageSize) {
            this.setData({
              showLoading: false
            })
          }
        };
      });
    }
  },
  // 搜索框事件
  searchValue: function (e) {
    this.setData({
      [`params.page`]: 1,
      [`dataList`]: [],
      [`showLoading`]: true,
      "showPage": false
    });
    this.getList();
  },
  // 日历选择
  onClose() {
    this.setData({
      show: false
    })
  },
  // 打开日历
  onDisplay() {
    this.setData({
      show: true
    });
  },
  // 确定日历
  onConfirm(e) {
    this.setData({
      "params.start_time": dateFormat(e.detail[0], "YYYY-MM-DD"),
      "params.end_time": dateFormat(e.detail[1], "YYYY-MM-DD"),
      "show": false
    })
  },
  // 上啦加载
  bindscrolltolower: function () {
    this.setData({
      "params.page": this.data.params.page += 1
    });
    this.getList();
  },
  // 分享
  onShow: function () {
    // 控制分享按钮
    wx.showShareMenu({
      withShareTicket: true,
      menus: ['shareAppMessage', 'shareTimeline'],
      success(res) {
        console.log('showShareMenu', res);
      }
    })
  }
})